#include <vtkForceDirectedLayoutStrategy.h>
#include <vtkGraphLayoutView.h>
#include <vtkMutableUndirectedGraph.h>
#include <vtkNamedColors.h>
#include <vtkNew.h>
#include <vtkRenderWindow.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkRenderer.h>

#include <vtkArcSource.h>
#include <vtkPolyDataMapper.h>
#include "vtkPolygon.h"
#include "vtkProperty.h"

#include "vtkLookupTable.h"
#include "vtkMinimalStandardRandomSequence.h"
#include "vtkCellData.h"

#include "vtkInteractorStyleTrackballCamera.h"
#include "vtkSphereSource.h"

#include <vector>

int main(int, char*[]) {
    vtkNew<vtkRenderer> renderer;
    vtkNew<vtkRenderWindow> renderWindow;
    renderWindow->SetWindowName("RegularPolygonSource");
    renderWindow->AddRenderer(renderer);
    vtkNew<vtkRenderWindowInteractor> renderWindowInteractor;
//    renderWindowInteractor->SetInteractorStyle(vtkNew<vtkInteractorStyleTrackballCamera>)
    renderWindowInteractor->SetRenderWindow(renderWindow);


    vtkNew<vtkNamedColors> colors;


    const int RowCount = 36;
    const int ColCount = 40;
    const double RowDegree = vtkMath::Pi() * 2 / RowCount;
    const double Radius = 500;
    const int AreaAvgRadius = Radius / ColCount;
    const int ArcSegmentCount = 1;
    double ArcSegmentDegree = RowDegree / ArcSegmentCount;
    double fyjDegree = 10.0;


    std::vector<float> xlist1;
    std::vector<float> ylist1;
    std::vector<float> xlist2;
    std::vector<float> ylist2;
    for (int j = 0; j < 10; ++j) {
        xlist1.push_back(j);
        ylist1.push_back(j * 0.1);
        xlist2.push_back(j);
        ylist2.push_back(j * 0.2);
    }

    vtkNew<vtkCellArray> allPolygons;
    vtkNew<vtkPoints> allPoints;
    vtkNew<vtkPolyData> polygonPolyData;

    for (int j = 0; j < xlist1.size(); ++j) {

        float x1 = xlist1.at(j);
        float y1 = ylist1.at(j);
        float x2 = xlist2.at(j);
        float y2 = ylist2.at(j);
        float p1[3] = {x1, y1, 0};
        float p2[3] = {x2, y2, 0};
        allPoints->InsertNextPoint(p1);
        allPoints->InsertNextPoint(p2);

        if (j > 0)  {
            vtkNew<vtkPolygon> polygon;
            polygon->GetPointIds()->SetNumberOfIds(4);
            vtkIdType numberOfPoints = allPoints->GetNumberOfPoints();


            polygon->GetPointIds()->SetId(0, numberOfPoints - 3);
            polygon->GetPointIds()->SetId(1, numberOfPoints - 4);
            polygon->GetPointIds()->SetId(2, numberOfPoints - 2);
            polygon->GetPointIds()->SetId(3, numberOfPoints -  1);

            allPolygons->InsertNextCell(polygon);
        }
    }


    polygonPolyData->SetPoints(allPoints);
    polygonPolyData->SetPolys(allPolygons);

    vtkNew<vtkPolyDataMapper> mapper;
    mapper->SetInputData(polygonPolyData);


    vtkNew<vtkActor> actor;
    actor->SetMapper(mapper);
    actor->GetProperty()->EdgeVisibilityOn();
//    actor->SetOrigin(-50, -50, 0);
    actor->SetPosition(-10, -10, 0);
    renderer->AddActor(actor);


    vtkNew<vtkSphereSource> sphere;
    sphere->SetRadius(0.2);
    vtkNew<vtkPolyDataMapper> sphereMapper;
    sphereMapper->SetInputConnection(sphere->GetOutputPort());
    vtkNew<vtkActor> sphereActor;
    sphereActor->SetMapper(sphereMapper);
    renderer->AddActor(sphereActor);

    renderWindow->Render();
    renderWindowInteractor->Initialize();
    renderWindowInteractor->Start();


    actor->Modified();
    renderWindow->Render();
    renderWindowInteractor->Render();



    return EXIT_SUCCESS;
}